package de.tabuma.sso.project;

import de.tabuma.sso.privileg.*;
import de.tabuma.customer.logik.CustomerFacade;
import de.tabuma.customer.entity.Customer;
import de.tabuma.sso.logik.*;
import java.util.*;
import de.tabuma.lib.contentmanagement.FacadeInterface;

/**
 * @author $Author: alefen $
 * @version $Revision: 1.1.1.1.2.1 $
 * @since $Date: 2010/01/08 10:03:24 $
 */
public class ProjectFacade implements  FacadeInterface {
    public static int create(Project project, String user) {
        return (int) PMF.doCreate(project, user);
    }

    public int createElement(Object object, String user) {
        return create((Project) object, user);
    }

    public static void update(Project project, String user) {
        PMF.doUpdate(project, user);
    }

    public void updateElement(Object object, String user) {
        update((Project) object, user);
    }

    public static void remove(int id, String user) {
        Project project = get(id);
        PMF.doRemove(project, user);

        List<Privileg> pList = PrivilegFacade.getList(id);
        for(int i=0;i<pList.size();i++) {
            Privileg privileg = pList.get(i);
            PrivilegFacade.remove(privileg.getId().intValue(), user);
        }
    }

    public void removeElement(int id, String user) {
        remove(id, user);
    }

    public static Project get(int id) {
        return PMF.get(id, new Project());
    }

    public Object getElement(int id) {
        return get(id);
    }
    
    public static List<Project> getList(int customerId) {
        String keys[] = new String[1];
        keys[0] = "customerId";
        String values[] = new String[1];
        values[0] = "" + customerId;
        return PMF.get(keys, values, new Project());
    }

    public static List<Project> getList(String user) {
        List<Customer> cList = CustomerFacade.getCustomer(user);
        List<Project> pList = new ArrayList<Project>();
        for(int i=0;i<cList.size();i++) {
            Customer customer = cList.get(i);
            List<Project> pList1 = getList(customer.getId().intValue());
            pList.addAll(pList1);
        }
        return pList;
    }

    public List getElementList(String user) {
        return getList(user);
    }


}
